package com.mdd.admin.controller.yylq;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.yylq.ITAppCourseService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.yylq.TAppCourseCreateValidate;
import com.mdd.admin.validate.yylq.TAppCourseSearchValidate;
import com.mdd.admin.validate.yylq.TAppCourseUpdateValidate;
import com.mdd.admin.vo.yylq.TAppCourseDetailVo;
import com.mdd.admin.vo.yylq.TAppCourseListedVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@RestController
@RequestMapping("/adminapi/yylq/course")
@Api(tags = "羊羊领企---商学院/课程管理")
public class TAppCourseController {

    @Resource
    ITAppCourseService iTAppCourseService;

    @GetMapping("/list")
    @ApiOperation(value="课程列表")
    public AjaxResult<PageResult<TAppCourseListedVo>> list(@Validated PageValidate pageValidate,
                                                           @Validated TAppCourseSearchValidate searchValidate) {
        PageResult<TAppCourseListedVo> list = iTAppCourseService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="课程详情")
    public AjaxResult<TAppCourseDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        TAppCourseDetailVo detail = iTAppCourseService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "课程新增")
    @PostMapping("/add")
    @ApiOperation(value="课程新增")
    public AjaxResult<Object> add(@Validated @RequestBody TAppCourseCreateValidate createValidate) {
        iTAppCourseService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "课程编辑")
    @PostMapping("/edit")
    @ApiOperation(value="课程编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody TAppCourseUpdateValidate updateValidate) {
        iTAppCourseService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "课程删除")
    @PostMapping("/del")
    @ApiOperation(value="课程删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iTAppCourseService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
